/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.businessservice.ctstour.service.Impl;

import com.dmgis.qxfw.dataservice.businessservice.api.domain.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.dz_warning;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.potential_points;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.warn_signal_info;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ForecastKey;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.DZWarning;
import com.dmgis.qxfw.dataservice.businessservice.common.util.DateTime;
import com.dmgis.qxfw.dataservice.businessservice.common.util.HttpRequestUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.JsonUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.StringUtil;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.ctstour.service.ICTSTourInfoService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("CTSTourInfo")
public class CTSTourInfoService implements ICTSTourInfoService {
    ProcessRequestController pro = new ProcessRequestController();
    HttpRequestUtil httpUtil = new HttpRequestUtil();

    @Override
    public ForecastKey getTownNewDate() {
        // TODO Auto-generated method stub
        ForecastKey newDate = new ForecastKey();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ForecastKey>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDateChar(DateTime.now().toDate());
            newDate.setNTimes(DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? 8 : 20);
        }
        return newDate;
    }

    @Override
    public List<tour_fcst> getTourFcstInfo(ForecastKey forecastKey) {
        // TODO Auto-generated method stub
        List<tour_fcst> resultList = new ArrayList<tour_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("areaname");
        columns.add("humid");
        columns.add("(cast(datechar as timestamp)+ cast((cast(timechar as integer)+ntimes)||'hour' as INTERVAL)) as datechar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("maxtemp");
        columns.add("minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        columns.add("advice");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(forecastKey.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", forecastKey.getStationID()));
        }
        if (forecastKey.getDateChar() != null) {
            strWhere.append(String.format(" and (cast(datechar as timestamp)+ cast((cast(timechar as integer)+ntimes)||'hour' as INTERVAL))>='%s'", new DateTime(forecastKey.getDateChar()).toDateTimeString()));
        }
        if (forecastKey.getEnddateChar() != null) {
            strWhere.append(String.format(" and (cast(datechar as timestamp)+ cast((cast(timechar as integer)+ntimes)||'hour' as INTERVAL))<='%s'", new DateTime(forecastKey.getEnddateChar()).toDateTimeString()));
        }
        strWhere.append(String.format(" and forecasttype='1'"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"(cast(datechar as timestamp)+ cast((cast(timechar as integer))||'hour' as INTERVAL)) desc"});
        try {
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_fcst>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<warn_signal_info> getWarningInfo(String startDate, String endDate, int id) {
        // TODO 预警信号表
        List<warn_signal_info> resultList = new ArrayList<warn_signal_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("Area");
        columns.add("Type");
        columns.add("Color");
        columns.add("City");
        columns.add("to_char(AnnouncedTime, 'yyyy-MM-dd HH24:MI:SS') as AnnouncedTime");
        columns.add("County");
        columns.add("Standard");
        columns.add("DefenseGuide");
        columns.add("AnnouncedTime");
        columns.add("bFree");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            whereCount++;
            strWhere.append(String.format("AnnouncedTime>='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and AnnouncedTime<='%s'", endDate));
        }
        if (id > 0) {
            strWhere.append(String.format(" and id=%d", id));
        }
        strWhere.append(" and bfree=0");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warn_signal_info>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<base_product> getTouristProduct(int id, String productType, String startDate, String endDate) {
        // TODO Auto-generated method stub
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        if (id > 0) {
            whereCount++;
            strWhere.append(String.format("id=%d", id));
        }
        if (!StringUtil.IsNullOrEmpty(productType)) {
            strWhere.append(String.format("and productType='%s'", productType));
        }
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format(" and forecastTime>='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and forecastTime<='%s'", endDate));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"forecastTime desc"});
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public ForecastKey getZhiShuNewestDate() {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        ForecastKey newDate = new ForecastKey();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam("cityid like 'XT%'");
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "zhishu");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ForecastKey>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setDateChar(DateTime.now().toDate());
            newDate.setTimeChar(DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? "08" : "20");
        }
        return newDate;
    }

    @Override
    public List<Map<String, Object>> getZhiShuInfo(ForecastKey forecastKey) {
        // TODO Auto-generated method stub
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(forecastKey.getStationID())) {
            whereCount++;
            strWhere.append(String.format("cityId='%s'", forecastKey.getStationID()));
        }
        if (forecastKey.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", forecastKey.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastKey.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", forecastKey.getTimeChar()));
        }
        if (!StringUtil.IsNullOrEmpty(forecastKey.getTourname())) {
            strWhere.append(String.format(" and cityname='%s'", forecastKey.getTourname()));
        }
        strWhere.append(" and cityId like 'XT%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "cityId ASC"});
        try {
            selectParam.put("method", "zhishu");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Map<String, Object>>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<tour_stations> getAllTourStations() {
        // TODO Auto-generated method stub
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return resultList;
    }

    @Override
    public List<tour_actual_img> getNewestActualImg() {
        // TODO Auto-generated method stub
        List<tour_actual_img> resultList = new ArrayList<tour_actual_img>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        try {
            String[] columns = new String[]{"to_char(max(datechar), 'yyyy-MM-dd HH24:MI:SS') as dateChar",
                    "stationid", "stationname"};
            selectRequest.setColumns(columns);
            selectParam.put("method", "tour_actual_img");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_actual_img>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<tour_actual_img> getImgGallery(String startDate, String endDate, String stationId) {
        // TODO Auto-generated method stub
        List<tour_actual_img> resultList = new ArrayList<tour_actual_img>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        try {
            String[] columns = new String[]{"to_char(max(datechar), 'yyyy-MM-dd HH24:MI:SS') as dateChar",
                    "stationid", "stationname", "imageName"};
            selectRequest.setColumns(columns);
            // 拼接where字段
            StringBuilder strWhere = new StringBuilder();
            int whereCount = 0;
            if (!StringUtil.IsNullOrEmpty(stationId)) {
                whereCount++;
                strWhere.append(String.format("stationid='%s'", stationId));
            }
            if (startDate != null) {
                strWhere.append(String.format(" and datechar>='%s'", startDate));
            }
            if (endDate != null) {
                strWhere.append(String.format(" and datechar<='%s'", endDate));
            }
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            selectRequest.setParam(strWhere.toString());
            selectParam.put("method", "tour_actual_img");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_actual_img>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<tour_stations> getTourStation() {
        // TODO 景点
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public String getstationid(tour_stations selecttour) {
        // TODO 更新
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String stationid = "";
        String[] columns = new String[]{"stationid"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("stationname='%s'", selecttour.getStationname()));
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (resultList.size() > 0)
            stationid = resultList.get(0).getStationid().toString().trim();
        return stationid;
    }

    @Override
    public String updatePoint(tour_stations selecttour, String stationid) {
        // TODO 更新
        String result = "";
        try {
            tour_stations toursta = new tour_stations();
            toursta.setStationname(selecttour.getStationname());
            toursta.setLongitude(selecttour.getLongitude());
            toursta.setLatitude(selecttour.getLatitude());
            toursta.setText(selecttour.getText());
            toursta.setGrade(selecttour.getGrade());
            toursta.setLocation(selecttour.getLocation());
            toursta.setPeople(selecttour.getPeople());
            toursta.setPhone(selecttour.getPhone());

            Map<String, String> updateParam = new HashMap<String, String>();
            RequestDataByUpdate<String, tour_stations> updateRequest = new RequestDataByUpdate<String, tour_stations>();
            updateRequest.setData(toursta);
            updateRequest.setParam(String.format("stationid='%s'", stationid));
            updateParam.put("method", "tour_stations");
            updateParam.put("sqlType", "update");
            updateParam.put("advCode", DbConfig.advCode);
            updateParam.put("param", JsonUtil.object2Json(updateRequest));
            result = pro.processRequest(updateParam);
        } catch (Exception e) {

        }
        return result;
    }

    @Override
    public String addPoint(tour_stations selecttour) {
        // TODO 添加
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String result = "";
        String id = "XT0000";
        String[] columns = new String[]{"stationid"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"stationid DESC"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        int idNum = 1;
        if (resultList.size() > 0) {
            result = "exist";
            id = resultList.get(0).getStationid().toString().trim();
            idNum = Integer.parseInt(id.substring(4, 6));
            idNum++;
        }
        try {
            List<tour_stations> List_toursta = new ArrayList<tour_stations>();
            tour_stations toursta = new tour_stations();
            String res = String.format("%4s", String.valueOf(idNum));
            res = res.replaceAll("\\s", "0");
            toursta.setStationid("XT" + res);
            toursta.setStationname(selecttour.getStationname());
            toursta.setLongitude(selecttour.getLongitude());
            toursta.setLatitude(selecttour.getLatitude());
            toursta.setText(selecttour.getText());
            toursta.setGrade(selecttour.getGrade());
            toursta.setLocation(selecttour.getLocation());
            toursta.setPeople(selecttour.getPeople());
            toursta.setPhone(selecttour.getPhone());
            List_toursta.add(toursta);
            Map<String, String> insertParam = new HashMap<String, String>();
            RequestDataByInsert<tour_stations> insertRequest = new RequestDataByInsert<tour_stations>();
            insertRequest.setData(List_toursta);
            insertParam.put("method", "tour_stations");
            insertParam.put("sqlType", "insert");
            selectParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(insertRequest));
            result = pro.processRequest(insertParam);
        } catch (Exception e) {

        }

        return result;
    }

    @Override
    public String deletePoint(tour_stations selecttour) {
        // TODO 删除
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String result = "";
        String stationid = "";
        String[] columns = new String[]{"stationid"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("stationname='%s'", selecttour.getStationname()));
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (resultList.size() > 0) {
            stationid = resultList.get(0).getStationid().trim();
            try {
                Map<String, String> deleteParam = new HashMap<String, String>();
                RequestDataByDelete<String> deleteRequest = new RequestDataByDelete<String>();
                deleteRequest.setParam(String.format("stationid='%s'", stationid));
                deleteParam.put("method", "tour_stations");
                deleteParam.put("sqlType", "delete");
                selectParam.put("advCode", DbConfig.advCode);
                deleteParam.put("param", JsonUtil.object2Json(deleteRequest));
                result = pro.processRequest(deleteParam);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }

    @Override
    public List<DZWarning> getDzpart(String bindid) {
        // TODO 地灾对应id的预警区
        List<dz_warning> listData = new ArrayList<dz_warning>();
        List<DZWarning> resultList = new ArrayList<DZWarning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(bindid)) {
            strWhere.append(String.format(" and docid='%s'", bindid));
        }
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc"});
        try {
            selectParam.put("method", "dz_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<dz_warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (dz_warning dzWarn : listData) {
                DZWarning dzWarning = new DZWarning();
                dzWarning.setDocid(dzWarn.getDocid());
                dzWarning.setDateChar(dzWarn.getDatechar());
                dzWarning.setPos(dzWarn.getPos());
                dzWarning.setGradeArea2(dzWarn.getGradearea2());
                dzWarning.setGradeArea3(dzWarn.getGradearea3());
                dzWarning.setGradeArea4(dzWarn.getGradearea4());
                dzWarning.setGradeArea5(dzWarn.getGradearea5());
                dzWarning.setDocpath(dzWarn.getDocpath());
                resultList.add(dzWarning);
            }
        }
        return resultList;
    }

    @Override
    public List<potential_points> getDisPoint(List<String> dpoint) {
        // TODO 获取关联灾害点的具体信息
        List<potential_points> listData = new ArrayList<potential_points>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (dpoint != null && dpoint.size() > 0) {
            strWhere.append(" and county in (");
            String tempString = "";
            for (String station : dpoint) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<travel_predict> getTourfcst(String fcst) {
        // TODO 获取特色旅游
        List<travel_predict> listData = new ArrayList<travel_predict>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(fcst)) {
            strWhere.append(String.format(" and type='%s'", fcst));
        }
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "travel_predict");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<travel_predict>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<tour_stations> getTourSta(List<String> stationnames) {
        // TODO 获取旅游景点坐标
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (stationnames != null && stationnames.size() > 0) {
            strWhere.append(" and stationname in (");
            String tempString = "";
            for (String station : stationnames) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return resultList;
    }

    @Override
    public List<cshx_zsyb> getFireIndex(String date) {
        // TODO Auto-generated method stub
        List<cshx_zsyb> listData = new ArrayList<cshx_zsyb>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("forcastdate");
        columns.add("fireindex");
        columns.add("firelevel");
        columns.add("stationname");
        columns.add("lon");
        columns.add("lat");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(date)) {
            strWhere.append(String.format(" and forcastdate='%s'", date));
        }
        strWhere.append(" and stationid like 'XT%'");
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "cshx_zsyb");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<cshx_zsyb>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<tour_stations> getImpdot(String stationname) {
        // TODO Auto-generated method stub
        List<tour_stations> resultList = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(stationname)) {
            strWhere.append(String.format(" and stationname='%s'", stationname));
        }
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return resultList;
    }

    @Override
    public cshx_zsyb initcshxPage() {
        // TODO Auto-generated method stub
        cshx_zsyb newDate = new cshx_zsyb();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(forcastdate, 'yyyy-MM-dd HH24:MI:SS') as forcastdate"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"forcastdate desc"});
        selectRequest.setLimit(1);
        selectRequest.setParam(" stationid like 'XT%'");
        try {
            selectParam.put("method", "cshx_zsyb");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            newDate = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<cshx_zsyb>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
            newDate.setForcastdate(DateTime.now().toDate());
        }
        return newDate;
    }

    @Override
    public List<tour_fcst> getTourPathfcst(List<String> stationnames, String time, String sc, String sx) {
        // TODO Auto-generated method stub
        List<tour_fcst> resultList = new ArrayList<tour_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(time)) {
            strWhere.append(String.format(" and datechar='%s'", time));
        }
        if (!StringUtil.IsNullOrEmpty(sc)) {
            strWhere.append(String.format(" and timechar='%s'", sc));
        }
        if (!StringUtil.IsNullOrEmpty(sx)) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 24, 0));
        }
        if (stationnames != null && stationnames.size() > 0) {
            strWhere.append(" and stationname in (");
            String tempString = "";
            for (String station : stationnames) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (!StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pro.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_fcst>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<tour_smallscale> getPointSK() {
        List<tour_smallscale> listData = new ArrayList<tour_smallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("observTime");
        columns.add("StationID");
        columns.add("Longitude");
        columns.add("Latitude");
        columns.add("rain");
        columns.add("CAST(replace(cast(DryBulbTemp AS VARCHAR),'-65535','99999') as float) as dryBulbTemp");
        columns.add("CAST(replace(cast(InstantWindV AS VARCHAR),'-65535','99999') as float) as instantWindV");
        columns.add("cast(replace(cast(RelHumidity AS VARCHAR),'-65535','99999') as integer) as relHumidity");
        columns.add("CAST(replace(cast(stationpress AS VARCHAR),'-65535','99999') as float) as stationpress");
        columns.add("StationName");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format("StationID='%s'", "XT0002"));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "tour_smallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message =pro.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_smallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }
}
